<?php 
class bot_order
{ 
	function order_bot_run() 
	{
		global $mysql_conn,$v_file;
		$user_id = $_COOKIE['user_id'];
		$bot_id = $_GET['bot_id'];
		$bot_state_type = array (
							"init"  => "初始状态",
							"loading" => "加载插件",
							"scaning"   => "等待手机扫码",
							"confirming" => "等待手机确认登录",
							"updating" => "更新账户信息",
							"running" => "运行中",
							"stop" => "停止运行",
							"client already exists" => "客户端已就绪",
							"client not exists" => "客户端不存在",
							"failure" => "没有找到客户端信息",
							"success" => "成功"
						);
		$sql = "SELECT * from `bot` WHERE `bot_id` = '".$bot_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$bot_user_id = $row['bot_user_id'];
		$bot_server_id = $row['bot_server_id'];
		if ($user_id == $bot_user_id) {
			if (file_exists("/server/tmp/mojo_weixin_state_".$bot_id.".json")) 
				{ 
					unlink ('/server/tmp/mojo_weixin_state_'.$bot_id.'.json');
				} 
			if (file_exists("/server/tmp/mojo_weixin_cookie_".$bot_id.".dat")) 
				{ 
					unlink ('/server/tmp/mojo_weixin_cookie_'.$bot_id.'.dat');
				}
			$sql = "SELECT * from `server` WHERE `server_id` = '".$bot_server_id."' ";
			$result = mysql_query($sql,$mysql_conn);
			@$row = mysql_fetch_array($result);
			$server_url = $row['server_url'];
			$url = $server_url."openwx/start_client?client=".$bot_id; 
			$html = file_get_contents($url);
			$contact = json_decode($html);
			$contact_code = $contact->{'code'};
			$contact_status = $contact->{'status'};
			$contact_state = $bot_state_type[$contact_status];
			if ($contact_code == "0") {
				$bot_state = "启动指令已发送，请耐心等待……".$contact_state;
			} else {
				$bot_state = "机器人启动失败，请关闭窗口重新启动。".$contact_state;
			}
		} else {
			$bot_state = "请勿非法提交数据！";
		}
		require($v_file);
	}
	function order_bot_stop() 
	{
		global $mysql_conn,$v_file;
		$user_id = $_COOKIE['user_id'];
		$bot_id = $_POST['bot_id'];
		$bot_state_type = array (
							"init"  => "初始状态",
							"loading" => "加载插件",
							"scaning"   => "等待手机扫码",
							"confirming" => "等待手机确认登录",
							"updating" => "更新账户信息",
							"running" => "运行中",
							"stop" => "停止运行",
							"client already exists" => "客户端已经就绪",
							"client not exists" => "客户端不存在",
							"failure" => "没有找到客户端信息",
							"success" => "成功"
						);
		$sql = "SELECT * from `bot` WHERE `bot_id` = '".$bot_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$bot_user_id = $row['bot_user_id'];
		$bot_server_id = $row['bot_server_id'];
		if ($user_id == $bot_user_id) {
			$sql = "SELECT * from `server` WHERE `server_id` = '".$bot_server_id."' ";
			$result = mysql_query($sql,$mysql_conn);
			@$row = mysql_fetch_array($result);
			$server_url = $row['server_url'];
			$url = $server_url."openwx/stop_client?client=".$bot_id; 
			$html = file_get_contents($url);
			$contact = json_decode($html);
			$contact_code = $contact->{'code'};
			$contact_status = $contact->{'status'};
			$contact_state = $bot_state_type[$contact_status];
			if ($contact_code == "0") {
				echo "2";//关闭成功
			} else {
				echo "1";//关闭失败
			}
		} else {
			echo "0";//非法提交
		}

	}
	function order_bot_cheak() 
	{
		global $mysql_conn,$v_file;
		$user_id = $_COOKIE['user_id'];
		$bot_id = $_POST['bot_id'];
		$bot_state_type = array (
							"init"  => "初始状态",
							"loading" => "加载插件",
							"scaning"   => "等待手机扫码",
							"confirming" => "等待手机确认登录",
							"updating" => "更新账户信息",
							"running" => "运行中",
							"stop" => "停止运行",
							"client already exists" => "客户端已经就绪",
							"client not exists" => "客户端不存在",
							"failure" => "没有找到客户端信息",
							"success" => "成功"
						);
		$sql = "SELECT * from `bot` WHERE `bot_id` = '".$bot_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$bot_user_id = $row['bot_user_id'];
		$bot_server_id = $row['bot_server_id'];
		if ($user_id == $bot_user_id) {
			$sql = "SELECT * from `server` WHERE `server_id` = '".$bot_server_id."' ";
			$result = mysql_query($sql,$mysql_conn);
			@$row = mysql_fetch_array($result);
			$server_url = $row['server_url'];
			$url = $server_url."openwx/check_client?client=".$bot_id; 
			@$html = file_get_contents($url);
			$contact = json_decode($html);
			$contact_code = $contact->{'code'};
			if ($contact_code == "0") {
				$contact_client = $contact->{'client'}[0];
				$contact_client_state = $contact_client->{'state'};
				if ($contact_client_state == "scaning") {
					echo "<h3 class='font-bold'><img src='".$server_url."openwx/get_qrcode?client=".$bot_id."' height='200' width='200' ></h3>";
				} else {
					echo "<h3 class='font-bold'>当前状态：".$bot_state_type[$contact_client_state]."</h3>";
				}
			} else if ($contact_code == "1"){
				echo "<h3 class='font-bold'>检测失败，请重新尝试！</h3>";
			} else {
				echo "<h3 class='font-bold'>未知错误</h3>";
			}
		} else {
			echo "<h3 class='font-bold'>请勿非法提交数据！";//非法提交
		}
	}
	function order_bot_main() 
	{
		global $mysql_conn,$v_file;
		$bot_id = $_GET['bot_id'];
		$sql = "SELECT * from `plus_bot` WHERE `plus_bot` = '".$bot_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$plus_list = $row['plus_list'];
		$plus_list_arr = explode(',',$plus_list); 
		$plus_list_count=count($plus_list_arr); 
		for($i=0;$i<$plus_list_count;$i++) 
		{
			$plus_id = $plus_list_arr[$i];
			$sql = "SELECT * from `plus` WHERE `plus_id` = '".$plus_id."' ";
			$result = mysql_query($sql,$mysql_conn);
			@$row = mysql_fetch_array($result);
			$plus_name = $row['plus_name'];
			$plus_access = $row['plus_access'];
			if ($i == 0) {
				$pluslist .= '<li class="list-group-item fist-item"><span class="pull-right"><button type="button" class="btn btn-primary btn-xs" onClick="plus('."'".$bot_id."'".",'".$plus_access."'".')" >管理</button></span> '.$plus_name.'</li>';
			} else {
				$pluslist .= '<li class="list-group-item"><span class="pull-right"><button type="button" class="btn btn-primary btn-xs" onClick="plus('."'".$bot_id."'".",'".$plus_access."'".')" >管理</button></span> '.$plus_name.'</li>';
			}
		}
		require($v_file);
	}
	function get_avatar($bot_id) 
	{
		global $mysql_conn,$v_file;
		$sql = "SELECT * from `bot` WHERE `bot_id` = '".$bot_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$bot_user_id = $row['bot_user_id'];
		$bot_server_id = $row['bot_server_id'];
		$sql = "SELECT * from `server` WHERE `server_id` = '".$bot_server_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$server_url = $row['server_url'];
		$url = $server_url."openwx/get_user_info?client=".$bot_id; 
		$html = file_get_contents($url);
		$contact = json_decode($html);
		$contact_id = $contact->{'id'};
		$avatar = $server_url."openwx/get_avatar?id=".$contact_id."&client=".$bot_id; 
		echo $avatar;
	}
	function get_user_info($bot_id,$code) 
	{
		global $mysql_conn,$v_file;
		$sql = "SELECT * from `bot` WHERE `bot_id` = '".$bot_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$bot_user_id = $row['bot_user_id'];
		$bot_server_id = $row['bot_server_id'];
		$sql = "SELECT * from `server` WHERE `server_id` = '".$bot_server_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$server_url = $row['server_url'];
		$url = $server_url."openwx/get_user_info?client=".$bot_id; 
		$html = file_get_contents($url);
		$contact = json_decode($html);
		$contact_echo = $contact->{$code};
		echo $contact_echo;
	}
	function check_client($bot_id) 
	{
		global $mysql_conn,$v_file;
		$sql = "SELECT * from `bot` WHERE `bot_id` = '".$bot_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$bot_user_id = $row['bot_user_id'];
		$bot_server_id = $row['bot_server_id'];
		$sql = "SELECT * from `server` WHERE `server_id` = '".$bot_server_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$server_url = $row['server_url'];
		$url = $server_url."openwx/check_client?client=".$bot_id; 
		$html = file_get_contents($url);
		$contact = json_decode($html);
		$bot_state_type = array (
							"init"  => "初始状态",
							"loading" => "加载插件",
							"scaning"   => "等待手机扫码",
							"confirming" => "等待手机确认登录",
							"updating" => "更新账户信息",
							"running" => "运行中",
							"stop" => "停止运行",
							"client already exists" => "命令成功执行",
							"failure" => "没有找到客户端信息"
						);
		$contact_client = $contact->{'client'}[0];
		$contact_client_state = $contact_client->{'state'};
		$contact_echo = $bot_state_type[$contact_client_state];
		echo $contact_echo;
	}
	function get_friend_info() 
	{
		global $mysql_conn,$v_file;
		$bot_id = $_POST['bot_id'];
		$sql = "SELECT * from `bot` WHERE `bot_id` = '".$bot_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$bot_user_id = $row['bot_user_id'];
		$bot_server_id = $row['bot_server_id'];
		$sql = "SELECT * from `server` WHERE `server_id` = '".$bot_server_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$server_url = $row['server_url'];
		$url = $server_url."openwx/get_friend_info?client=".$bot_id; 
		if (!empty($_POST['sousuokey'])) $url = $server_url."openwx/search_friend?displayname=".urlencode($_POST['sousuokey'])."&client=".$bot_id; 
		$html = file_get_contents($url);
		$contact = json_decode($html);
		foreach ($contact as $key=>$value)
		{
			$friend_account = $value->{'account'};
			$friend_name = $value->{'name'};
			$friend_id = $value->{'id'};
			$friend_displayname = $value->{'displayname'};
			$friend_avatar_url = $server_url."openwx/get_avatar?id=".$friend_id."&client=".$bot_id; 
			$friend_category = $value->{'category'};
			if ($friend_category != "公众号") {
				$friend_list.= '<tr><td class="client-avatar"><img alt="image" src="'.$friend_avatar_url.'"> </td>';
				$friend_list.= '<td><a data-toggle="tab" href="weibot_friend.php?m=view?weibot_id='.$bot_id.'&friendid='.$friend_id.'" name="'.$friend_name.'" class="client-link">'.$friend_name.'</a></td>';
				$friend_list.= '<td> '.$friend_displayname.'</td>';
				$friend_list.= '<td class="contact-type"><i class="fa fa-comments"> </i></td>';
				$friend_list.= '<td> '.$friend_account.'</td>';
				$friend_list.= '<td class="client-status"><a href="#" onClick="info_view('."'search_friend'".",'".$friend_id."'".')" ><span class="label label-primary">详情</span></a></td></tr>';
			}	
		}
		echo $friend_list;			
	}
	
	function get_group_info() 
	{
		global $mysql_conn,$v_file;
		$bot_id = $_POST['bot_id'];
		$sql = "SELECT * from `bot` WHERE `bot_id` = '".$bot_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$bot_user_id = $row['bot_user_id'];
		$bot_server_id = $row['bot_server_id'];
		$sql = "SELECT * from `server` WHERE `server_id` = '".$bot_server_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$server_url = $row['server_url'];
		$url = $server_url."openwx/get_group_info?client=".$bot_id; 
		if (!empty($_POST['sousuokey'])) $url = $server_url."openwx/search_group?displayname=".urlencode($_POST['sousuokey'])."&client=".$bot_id;
		$html = file_get_contents($url);
		$contact = json_decode($html);
		foreach ($contact as $key=>$value)
		{
			$group_displayname = $value->{'displayname'};
			$group_id = $value->{'id'};
			$group_member = $value->{'member'};
			$group_member_num = count($group_member);
			$group_avatar_url = $server_url."openwx/get_avatar?id=".$group_id."&client=".$bot_id; 			
			$group_list.= '<tr><td class="client-avatar"><img alt="image" src="'.$group_avatar_url.'"> </td>';
			$group_list.= '<td><a data-toggle="tab" href="weibot_friend.php?m=view$weibot_id='.$client.'&friendid='.$group_id.'" class="client-link">'.$group_displayname.'</a></td>';
			$group_list.= '<td></td><td class="contact-type"><i class="fa fa-comments"> </i></td>';
			$group_list.= '<td>成员：'.$group_member_num.' 人</td>';
			$group_list.= '<td class="client-status"><a href="#" onClick="info_view('."'search_group'".",'".$group_id."'".')" ><span class="label label-primary">详情</span></a></td></tr>';						
		}
		echo $group_list;
	}
	function get_category_info() 
	{
		global $mysql_conn,$v_file;
		$bot_id = $_POST['bot_id'];
		$sql = "SELECT * from `bot` WHERE `bot_id` = '".$bot_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$bot_user_id = $row['bot_user_id'];
		$bot_server_id = $row['bot_server_id'];
		$sql = "SELECT * from `server` WHERE `server_id` = '".$bot_server_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$server_url = $row['server_url'];
		$url = $server_url."openwx/get_friend_info?client=".$bot_id; 
		if (!empty($_POST['sousuokey'])) $url = $server_url."openwx/search_friend?displayname=".urlencode($_POST['sousuokey'])."&client=".$bot_id; 
		$html = file_get_contents($url);
		$contact = json_decode($html);
		foreach ($contact as $key=>$value)
		{
			$category_account = $value->{'account'};
			$category_name = $value->{'name'};
			$category_id = $value->{'id'};
			$category_displayname = $value->{'displayname'};
			$category_avatar_url = $server_url."openwx/get_avatar?id=".$category_id."&client=".$bot_id; 
			$category_category = $value->{'category'};
			if ($category_category == "公众号") {
				$category_list.= '<tr><td class="client-avatar"><img alt="image" src="'.$category_avatar_url.'"> </td>';
				$category_list.= '<td><a data-toggle="tab" href="weibot_friend.php?m=view$weibot_id='.$bot_id.'&friendid='.$category_id.'" name="'.$category_name.'" class="client-link">'.$category_name.'</a></td>';
				$category_list.= '<td> '.$category_displayname.'</td>';
				$category_list.= '<td class="contact-type"><i class="fa fa-comments"> </i></td>';
				$category_list.= '<td> '.$category_account.'</td>';
				$category_list.= '<td class="client-status"><a href="#" onClick="info_view('."'search_friend'".",'".$category_id."'".')" ><span class="label label-primary">详情</span></a></td></tr>';
			}	
		}
		echo $category_list;
	}
	function info_view_do() 
	{
		global $mysql_conn,$v_file;
		$bot_id = $_POST['bot_id'];
		$info_type = $_POST['info_type'];
		$info_id = $_POST['info_id'];
		$sql = "SELECT * from `bot` WHERE `bot_id` = '".$bot_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$bot_user_id = $row['bot_user_id'];
		$bot_server_id = $row['bot_server_id'];
		$sql = "SELECT * from `server` WHERE `server_id` = '".$bot_server_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$server_url = $row['server_url'];
		$url = $server_url."openwx/".$info_type."?id=".$info_id."&client=".$bot_id; 
		$html = file_get_contents($url);
		$contact = json_decode($html);
		foreach ($contact as $key=>$value)
		{
			if ($info_type == "search_group") {
				$info_avatar_url = $server_url."openwx/get_avatar?id=".$info_id."&client=".$bot_id; 
				$info_displayname = $value->{'displayname'};//显示名字
				$info_id = $value->{'id'};//显示名字
				$info_member = $value->{'member'};//显示名字
                $info_list.= '<div class="full-height-scroll"><div class="table-responsive"><table class="table table-striped table-hover"><tbody><tr>';
				$info_list.= '<td class="client-avatar"><img alt="image" src="'.$info_avatar_url.'"> </td>';
				$info_list.= '<td><a data-toggle="tab" href="#contact-1" class="client-link">'.$info_displayname.'</a></td>';
				$info_list.= '<td class="client-status"> <span class="label label-primary" onClick="new_groupname('."'".$bot_id."'".",'".$info_id."'".')" >修改群名称</span> ';
				$info_list.= ' <span class="label label-primary" onClick="invite_friend ('."'".$bot_id."'".",'".$info_id."'".')" >邀请好友</span> </td></tr>';
				foreach ($info_member as $key=>$value_member)
				{
					$info_member_id = $value_member->{'id'};//成员ID
					$info_member_displayname = $value_member->{'displayname'};//显示名字
					$info_member_name = $value_member->{'name'};//微信名字
					$info_member_account = $value_member->{'account'};//微信号
					$info_member_markname = $value_member->{'markname'};//备注姓名
					$info_member_province = $value_member->{'province'};//省份
					$info_member_city = $value_member->{'city'};//城市
					$info_member_signature = $value_member->{'signature'};//个人签名
					$info_list.= '<tr><td class="client-avatar"></td>';
					$info_list.= '<td><a data-toggle="tab" href="#contact-1" class="client-link">'.$info_member_displayname.'</a></td>';
					$info_list.= '<td class="client-status">';
					$info_list.= ' <span class="label label-red" onClick="make_friend('."'".$bot_id."'".",'".$info_member_id."'".')" >添加好友</span> ';
					$info_list.= ' <span class="label label-red" onClick="kick_group_member('."'".$bot_id."'".",'".$info_id."','".$info_member_id."'".')" >移除</span> ';
					$info_list.= '</td></tr>';
				}
                $info_list.= '</tbody></table></div></div>';
			} else {
				$info_avatar_url = $server_url."openwx/get_avatar?id=".$info_id."&client=".$bot_id; 
				$info_displayname = $value->{'displayname'};//显示名字
				$info_name = $value->{'name'};//微信名字
				$info_account = $value->{'account'};//微信号
				$info_category = $value->{'category'};//省份
				$info_markname = $value->{'markname'};//备注姓名
				$info_province = $value->{'province'};//省份
				$info_city = $value->{'city'};//城市
				$info_signature = $value->{'signature'};//个人签名
				$info_list.= '<div class="contact-box" style="border-width:0px"><div class="col-sm-4"><div class="text-center">';
				$info_list.= '<img alt="image" class="img-circle m-t-xs img-responsive" src="'.$info_avatar_url.'">';
				$info_list.= '<div class="m-t-xs font-bold">'.$info_displayname.'</div>';
				$info_list.= '</div></div><div class="col-sm-8">';
				$info_list.= '<h3><strong>'.$info_name.'</strong></h3>';
				$info_list.= '<p> 微信号：'.$info_account.'</p>';
				if ($info_category != "公众号") $info_list.= '<p id="now_markname"> 备  注：'.$info_markname.' <button type="button" class="btn btn-primary btn-xs" onClick="new_markname('."'".$bot_id."'".",'".$info_id."'".')" >修改备注</button></p>';
				$info_list.= '<p> 地  址： '.$info_province.$info_city.'</p>';
				$info_list.= '<address>签名：'.$info_signature.'</address></div></div>';
			}
		}
		echo $info_list;
	}
	function set_markname() 
	{
		global $mysql_conn,$v_file;
		$bot_id = $_POST['bot_id'];
		$objet_id = $_POST['objet_id'];
		$objet_new_markname = urlencode($_POST['objet_new_markname']);
		$sql = "SELECT * from `bot` WHERE `bot_id` = '".$bot_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$bot_user_id = $row['bot_user_id'];
		$bot_server_id = $row['bot_server_id'];
		$sql = "SELECT * from `server` WHERE `server_id` = '".$bot_server_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$server_url = $row['server_url'];
		$url = $server_url."openwx/set_markname"."?id=".$objet_id."&new_markname=".$objet_new_markname."&client=".$bot_id; 
		$html = file_get_contents($url);
		$contact = json_decode($html);
		$contact_code = $contact->{'code'};
		if ($contact_code == "0") {
			echo "修改成功，请重新打开好友详情查看";
		} else {
			echo "修改失败，请确保新备注不含有特殊字符";
		}
	}
	function set_group_displayname() 
	{
		global $mysql_conn,$v_file;
		$bot_id = $_POST['bot_id'];
		$objet_id = $_POST['objet_id'];
		$objet_new_groupname = urlencode($_POST['objet_new_groupname']);
		$sql = "SELECT * from `bot` WHERE `bot_id` = '".$bot_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$bot_user_id = $row['bot_user_id'];
		$bot_server_id = $row['bot_server_id'];
		$sql = "SELECT * from `server` WHERE `server_id` = '".$bot_server_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$server_url = $row['server_url'];
		$url = $server_url."openwx/set_group_displayname"."?id=".$objet_id."&new_displayname=".$objet_new_groupname."&client=".$bot_id; 
		$html = file_get_contents($url);
		$contact = json_decode($html);
		$contact_code = $contact->{'code'};
		if ($contact_code == "0") {
			echo "修改成功，请重新打开群详情页查看";
		} else {
			echo "修改失败，请确保新群名称不含有特殊字符";
		}
	}
	function make_friend() 
	{
		global $mysql_conn,$v_file;
		$bot_id = $_POST['bot_id'];
		$objet_id = $_POST['objet_id'];
		$objet_verify = urlencode($_POST['objet_verify']);
		$sql = "SELECT * from `bot` WHERE `bot_id` = '".$bot_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$bot_user_id = $row['bot_user_id'];
		$bot_server_id = $row['bot_server_id'];
		$sql = "SELECT * from `server` WHERE `server_id` = '".$bot_server_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$server_url = $row['server_url'];
		$url = $server_url."openwx/make_friend"."?id=".$objet_id."&verify=".$objet_verify."&client=".$bot_id; 
		$html = file_get_contents($url);
		$contact = json_decode($html);
		$contact_code = $contact->{'code'};
		if ($contact_code == "0") {
			echo "请求发送成功，附加消息：".$_POST['objet_verify'];
		} else {
			echo "请求发送失败，请重新尝试";
		}
	}
	function kick_group_member() 
	{
		global $mysql_conn,$v_file;
		$bot_id = $_POST['bot_id'];
		$objet_id = $_POST['objet_id'];
		$objet_member = $_POST['objet_member'];
		$sql = "SELECT * from `bot` WHERE `bot_id` = '".$bot_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$bot_user_id = $row['bot_user_id'];
		$bot_server_id = $row['bot_server_id'];
		$sql = "SELECT * from `server` WHERE `server_id` = '".$bot_server_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$server_url = $row['server_url'];
		$url = $server_url."openwx/kick_group_member"."?id=".$objet_id."&member=".$objet_member."&client=".$bot_id; 
		$html = file_get_contents($url);
		$contact = json_decode($html);
		$contact_code = $contact->{'code'};
		if ($contact_code == "0") {
			echo "移除群成员成功";
		} else {
			echo "移除群成员失败，请重新尝试";
		}
	}
	function invite_friend() 
	{
		global $mysql_conn,$v_file;
		$bot_id = $_POST['bot_id'];
		$group_id = $_POST['group_id'];
		$sql = "SELECT * from `bot` WHERE `bot_id` = '".$bot_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$bot_user_id = $row['bot_user_id'];
		$bot_server_id = $row['bot_server_id'];
		$sql = "SELECT * from `server` WHERE `server_id` = '".$bot_server_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$server_url = $row['server_url'];
		$url = $server_url."openwx/get_friend_info?client=".$bot_id; 
		$html = file_get_contents($url);
		$contact = json_decode($html);
		$friend_list.= '<div class="full-height-scroll"><div class="table-responsive"><table class="table table-striped table-hover"><tbody>';
		foreach ($contact as $key=>$value)
		{
			$friend_account = $value->{'account'};
			$friend_name = $value->{'name'};
			$friend_id = $value->{'id'};
			$friend_displayname = $value->{'displayname'};
			$friend_avatar_url = $server_url."openwx/get_avatar?id=".$friend_id."&client=".$bot_id; 
			$friend_category = $value->{'category'};
			if ($friend_category != "公众号") {
				$friend_list.= '<tr><td class="client-avatar"><img alt="image" src="'.$friend_avatar_url.'"> </td>';
				$friend_list.= '<td><a data-toggle="tab" href="weibot_friend.php?m=view?weibot_id='.$bot_id.'&friendid='.$friend_id.'" name="'.$friend_name.'" class="client-link">'.$friend_name.'</a></td>';
				$friend_list.= '<td> '.$friend_displayname.'</td>';
				$friend_list.= '<td class="contact-type"><i class="fa fa-comments"> </i></td>';
				$friend_list.= '<td> '.$friend_account.'</td>';
				$friend_list.= '<td class="client-status"><a href="#" onClick="invite_friend_do('."'".$bot_id."','".$group_id."','".$friend_id."'".')" ><span class="label label-primary">邀请</span></a></td></tr>';
			}	
		}
		$friend_list.= '</tbody></table></div></div>';
		echo $friend_list;
	}
	function invite_friend_do() 
	{
		global $mysql_conn,$v_file;
		$bot_id = $_POST['bot_id'];
		$group_id = $_POST['group_id'];
		$member_id = $_POST['member_id'];
		$sql = "SELECT * from `bot` WHERE `bot_id` = '".$bot_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$bot_user_id = $row['bot_user_id'];
		$bot_server_id = $row['bot_server_id'];
		$sql = "SELECT * from `server` WHERE `server_id` = '".$bot_server_id."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$server_url = $row['server_url'];
		$url = $server_url."openwx/invite_friend?id=".$group_id."&friend=".$member_id."&client=".$bot_id; 
		$html = file_get_contents($url);
		$contact = json_decode($html);
		$contact_code = $contact->{'code'};
		if ($contact_code == "0") {
			echo "邀请好友入群成功";
		} else {
			echo "邀请好友入群失败，请重新尝试";
		}
	}
	
	
} 
/* End of file democontroller.php */ 